<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/component/commonTagLib.jsp" %>

<!DOCTYPE html>
<html>
<head>
    <title>招标密码管理</title>
    <%@ include file="/WEB-INF/component/commonCSS.jsp" %>
    <link href="${ctx}/lib/plugins/zTree_v3/css/zTreeStyle/zTreeStyle.css" rel="stylesheet" />
    <style type="text/css">
    	table.privilegeTable {
    		width: 100%;
    		border-collapse: collapse;
    		border: 1px solid #ccc;
    	}
    	div.ztreePanel {
    		max-height: 450px;
    		min-height: 390px;
    		overflow: auto;
    	}
    	div.ztree {
    		margin: 20px;
    	}
    	.leftTd {
    		vertical-align: top;
    	}
    	.rightTd {
    		width: 50%;
    		height: 100%;
    		vertical-align: top;
    		border-left: 1px solid #ccc;
    	}
    	
    	div.rightTitleDiv {
    		font-size: 20px;
    		margin: 10px 0px 20px 0px;
    		padding: 10px 20px;
    		border-bottom: 1px solid #ccc;
    	}
    	
    	div.rightTextDiv {
    		margin: 10px 0px;
    		padding: 5px 20px;
    	}
    	div.box-body {
    		margin-top:7px;
    	}
    	
    	/*h3{
    	margin-top:0px;
    	margin-bottom:-10px;
    	margin-left:110px;
    	font-family:"黑体";
    	color:#06507b;
    	font-size:22px;
    	}*/
    </style>
</head>
<body class="skin-blue sidebar-mini fixed skin-blue-light-frame">
    <section class="content-header">
        <h1>${(opType==0)?"密码设置":"密码设置"}</h1>
        <ol class="breadcrumb">
            <li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i>首页</a></li>
            <li class="active"><a href="#">药品招标管理</a></li>
            <li class="active"><a href="#">采购项目管理</a></li>
            <li class="active"><a href="#">招标密码管理</a></li>
        </ol>
    </section>
    <section class="content">
    <form role="form" id="form" class="form-horizontal" action="setPassword.html" method="post">
            	<input type="hidden" name=projId value="${data.projId}" />
            	<input type="hidden" name=passwordCount value="${data.passwordCount}" />
            	<input type="hidden" name=firstSetPswd value="${data.firstSetPswd}" />
        <div class=" box box-success ">   
         <div style="position: absolute;bottom:45px;right:10px;">
             <img src="/medstgmini/lib/img/SetPassword.png">
         </div>       
         <input type="password"  style="display:none;">
         <div class="box-header with-border">
		  <h3 class="box-title ">${name}</h3>
		 </div>
		 <div class="box-body">
                        	<c:choose>
                        		<c:when test="${data.firstSetPswd}">
                        		<c:forEach var="i" begin="1" end="${data.passwordCount}" varStatus="passwordCount"> 
                        			<div class="form-group form-group-xs">
				                        <label for="newpassword" class="col-sm-2 text-right">密码${i}：</label>
					                        <div class="col-sm-5 text-left">
					                            <input type="password"  autocomplete="off" class="form-control " id="password${i}" name="password${i}" placeholder="密码${i}" >
					                        </div>
			                    	</div>
			                    	<div class="form-group form-group-xs">
				                        <label for="newpassword" class="col-sm-2 text-right">确认密码${i}：</label>
					                        <div class="col-sm-5 text-left">
					                            <input class="form-control" id="passwordConfirm${i}" name="passwordConfirm${i }" placeholder="确认密码${i }" type="password">
					                        </div>
			                    	</div>
			                    	</c:forEach>
                        		</c:when>
                        		
                        	<c:otherwise>
	                        	<c:if test="${!empty data.firstSetPswd }">
	                        		<c:forEach var="i" begin="1" end="${data.passwordCount}" varStatus="passwordCount"> 
	                        			<div class="form-group form-group-xs">
					                        <label for="newpassword" class="col-sm-2 text-right">当前密码${i}：</label>
						                        <div class="col-sm-5 text-left">
						                            <input class="form-control" id="password${i}" name="password${i}" placeholder="密码${i}" type="password">
						                        </div>
				                    	</div>
				                    	<div class="form-group form-group-xs">
					                        <label for="newpassword" class="col-sm-2 text-right">新密码${i}：</label>
						                        <div class="col-sm-5 text-left">
						                            <input class="form-control" id="newPassword${i}" name="newPassword${i}" placeholder="新密码${i}" type="password">
						                        </div>
				                    	</div>
				                    	<div class="form-group form-group-xs">
					                        <label for="newpassword" class="col-sm-2 text-right">确认密码${i}：</label>
						                        <div class="col-sm-5 text-left">
						                            <input class="form-control" id="newPasswordConfirm${i}" name="newPasswordConfirm${i }" placeholder="确认密码${i }" type="password">
						                        </div>
				                    	</div>
				                    </c:forEach>
				                </c:if>
                        	</c:otherwise>
                        </c:choose>
                        <div class="form-group form-group-xs">
					        <label for="newpassword" class="col-sm-2 text-right"><i class="fa fa-exclamation-circle fa-lg" style="color:#dd4b39;"></i>&nbsp;<span style="color:#dd4b39;font-weight:600">提示：</span></label>					        
						    <div class="col-sm-10 text-left" style="color:#dd4b39">
						            密码长度为6-12位且包含有大写字母、小写字母、数字和特殊字符('~!@#$%^&*()_+`\-={}:'<>?,.\/')组成
						    </div>
				         </div>
				         
                        <!--  <div class="form-group form-group-xs" >
		                        <label for="newpassword" class="col-sm-5 text-left">><span style="color:red">密码长度为6-12位且包含有大写字母、小写字母、数字和特殊字符('~!@#$%^&*()_+`\-={}:'<>?,.\/')组成<span></label>
	                    	</div>-->
                </div>
                <div class="box-footer text-center">
                    <button type="button" class="btn btn-success btn-sm" onclick="submitPassword();">保&nbsp;存</button>
                    <%-- <a href="${ctx}/bidProject/toPassWord.html" class="btn btn-danger btn-sm back">返&nbsp;回</a> --%>
                    <a href="javascript:history.go(-1)" class="btn btn-danger btn-sm back">返&nbsp;回</a>
                </div>
           </div>
      </form>
    </section>
    
    <%@ include file="/WEB-INF/component/commonJS.jsp" %>
    <script src="${ctx}/lib/plugins/zTree_v3/js/jquery.ztree.all-3.5.min.js"></script>
    
    <script type="text/javascript">
    $(function(){
    	var defalutProjId = "${defalutProjId}";
		if(defalutProjId!=null && defalutProjId!=""){
			$("a.btn-danger").remove();
		}
    })
    
    	function submitPassword() {
    		var passwordCount = "${data.passwordCount}";
    		var passwords ="";
    		var firstSetPswd = "${data.firstSetPswd}";
    		var parn = /^(?=.*[A-Z])(?=.*[a-z])(?=.*\d)(?=.*[~!@#$%^&*()_+`\-={}:";'<>?,.\/]).{6,12}$/;
			if( firstSetPswd!="true" ){
				for(var i = 1; i<= passwordCount;i++){
					var password = $.trim($("#password"+i).val());
					var newPassword = $.trim($("#newPassword"+i).val());
					var newPasswordConfirm = $.trim($("#newPasswordConfirm"+i).val());
					
					if (password == null || password == "") {
						$.HN.message.alert("请输入当前密码"+i+"！", "消息", "warn");
						return false;
					}
					if (newPassword == null || newPassword == "") {
						$.HN.message.alert("请输入新密码"+i+"！", "消息", "warn");
						return false;
					}
					if( newPassword.length < 6){
						$.HN.message.alert("新密码长度为6-12位！", "消息", "warn");
						return;
					}
					if( newPassword.length > 12){
						$.HN.message.alert("新密码长度为6-12位！", "消息", "warn");
						return;
					}
					if (!(parn.test(newPassword))){
						$.HN.message.alert("新密码"+i+"至少有一个大写字母、一个小写字母、数字和一个特殊字符('~!@#$%^&*()_+`\-={}:'<>?,.\/')组成", "消息", "warn");
						return false 
					}
					if (newPasswordConfirm == null || newPasswordConfirm == "") {
						$.HN.message.alert("请输入确认密码"+i+"！", "消息", "warn");
						return false;
					}
					if( newPasswordConfirm!=newPassword){
						$.HN.message.alert("新密码"+i+"与确认密码不相同", "消息", "warn");
						return;
					}
				}
			}else{
	    		for(var i = 1; i<= passwordCount;i++){
					var password = $.trim($("#password"+i).val());
					var passwordConfirm = $.trim($("#passwordConfirm"+i).val());
					if (password == null || password == "") {
						$.HN.message.alert("请输入密码"+i+"！", "消息", "warn");
						return false;
					}
					if( password.length < 6){
						$.HN.message.alert("密码长度为6-12位！", "消息", "warn");
						return;
					}
					if( password.length > 12){
						$.HN.message.alert("密码长度为6-12位！", "消息", "warn");
						return;
					}
					if (!(parn.test(password))){
						$.HN.message.alert("密码"+i+"至少有一个大写字母、一个小写字母、数字和一个特殊字符('~!@#$%^&*()_+`\-={}:'<>?,.\/')组成", "消息", "warn");
						return false 
					} 
					if (passwordConfirm == null || passwordConfirm == "") {
						$.HN.message.alert("请输入确认密码"+i+"！", "消息", "warn");
						return false;
					}
					if( passwordConfirm!=password){
						$.HN.message.alert("密码"+i+"与确认密码不相同", "消息", "warn");
						return;
					}
				}
			}
			$('#form').submit();
    	}
    
		$('#form').ajaxForm({
	    dataType: 'json', 
    	success: function(returnData) {
    	if(returnData.success) {
    		$.HN.message.alert('保存成功！', '提示信息', 'success');
    		window.setTimeout("document.location.href='${ctx}/bidProject/toPassWord.html'",500); 
		}else{
			$.HN.message.alert("保存失败！"+returnData.msg+"", '提示信息', 'error');
    	}
       } 	
   });
    	
    	
    	
    	
    	
    
    </script>
    
</body>
</html>
